<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class CI_Schedule_entity{
	var $current_dbprefix = "";
	var $CI;
	var $id = 0;
	var $escort_id = 0;
	var $week_day = 0;
	var $from = "";
	var $to = "";
	
	function __construct() {
		$this->CI = &get_instance();
		$this->current_dbprefix = $this->CI->db->dbprefix;
		$this->CI->db->set_dbprefix('default_');
	}
	function __destruct() {
		$this->CI->db->set_dbprefix($this->current_dbprefix);
	}
	
	function setEscortId($input){
		$this->escort_id=$input;
	}
	function setWeekDay($input){
		$this->week_day =$input;
	}
	function setFrom($input){
		$this->from =$input;
	}
	function setTo($input){
		$this->to =$input;
	}
	function getId(){
		return $this->id;
	}
	function getEscortId(){
		return $this->escort_id;
	}
	function getWeekDay(){
		return $this->week_day;
	}
	function getFrom(){
		return $this->from;
	}
	function getTo(){
		return $this->to;
	}
	
	function init($cmd, $input)
	{
		if($cmd == 'id'){
			$result = $this->CI->db->where('id',$input)->get(TBL_SCHEDULE)->result();
		}else{
			return false;
		}
		if( !empty($result) ){
			$this->id = $result[0]->id;
			$this->escort_id = $result[0]->escort_id;
			$this->week_day = $result[0]->week_day;
			$this->from = $result[0]->from;
			$this->to = $result[0]->to;
			return $this;
		}
		return false;
	}
	function getScheduleList(){
		return $this->CI->db->get(TBL_SCHEDULE)->result();
	}
	function save(){
		$this->CI->db->set('escort_id',$this->getEscortId());
		$this->CI->db->set('week_day',$this->getWeekDay());
		$this->CI->db->set('from',$this->getFrom());
		$this->CI->db->set('to',$this->getTo());
		$this->CI->db->insert(TBL_SCHEDULE);
		return $this->CI->db->insert_id();
	}
	function update(){
		$this->CI->db->set('escort_id',$this->getEscortId());
		$this->CI->db->set('week_day',$this->getWeekDay());
		$this->CI->db->set('from',$this->getFrom());
		$this->CI->db->set('to',$this->getTo());
		return $this->CI->db->where('id', $this->id)->update(TBL_SCHEDULE);
	}
	function delete($id){
		$this->CI->db->where('id',$id);
		$this->CI->db->delete(TBL_SCHEDULE);
	}
}